import csv
import pandas as pd
import matplotlib.pyplot as plt
import time
from matplotlib.animation import FuncAnimation
from pandasgui import show
import numpy as np



with open("C:\qx\data\hmpd.csv") as f:
    reader = csv.reader(f)

    header_row = next(reader)
    print(header_row)

    
  
    for row in reader:
        points = []
        index = 0
        while(index < len(row)):
            if header_row[index].find("_P") > 0:
                points.append((float(row[index]),float(row[index +
                1]),float(row[index + 2])))
                index+=3
            else:
                index+=1
        df = pd.DataFrame(points,columns = ['x','y','z'])
        show(df)
       

 
  

    fig = plt.figure()

   

    datas = []
    rowIndex = 0

    

    points = plt.scatter([],[])

    for row in reader:
        xPoints = []
        yPoints = []
        zPoints = []
        index = 0
        while(index < len(row)):
            if header_row[index].find("_P") > 0:
                xPoints.append(float(row[index]))
                yPoints.append(float(row[index + 1]))
                zPoints.append(float(row[index + 2]))
                index+=3
            else:
                index+=1

        datas.append((xPoints,yPoints,zPoints))
 

    def update(frame):
        
        global rowIndex,datas,points

        #points.set_data(datas[rowIndex][0],datas[rowIndex][1])
        #points.set_offsets([datas[rowIndex][0], datas[rowIndex][1]])
        
        plt.cla()
        temp= plt.scatter(datas[rowIndex][0], datas[rowIndex][1])
        rowIndex = rowIndex + 1

        return temp

    

    ani = FuncAnimation(fig, func=update, interval = 40)
    plt.show()

